package com.example.myapplication.status2;


import java.util.Random;
import java.util.Timer;
import java.util.TimerTask;

public class StatusInstall extends Status {
    public StatusInstall(StatusContext statusContext) {
        super(statusContext);
    }

    @Override
    public void doAction() {
        FileUtils.getSingleExcutor().execute(() -> {
            new Timer().schedule(new TimerTask() {
                @Override
                public void run() {
                    boolean installSuccess = new Random().nextBoolean();
                    if (installSuccess) {
                        statusContext.setStatus(new StatusOpen(statusContext));
                    } else {
                        statusContext.setStatus(new StatusInstallFailed(statusContext));
                    }
                }
            }, 2000);
        });
    }

    @Override
    public void translateStatus() {
        System.out.println("status - 正在安装");
        statusContext.updateView(Event.INSTALL);
    }

    @Override
    public void eventChange(Event event) {
        doAction();
    }
}
